#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
/*
simple implemment
*/

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    int k;
    int min_len, max_len;
    int len = 0;
    bool flag = false;
    int cnt = 0;
    cin >> s >> k;

    for(int i = 0; i < s.length(); i ++){
        if(s[i] != '?' && s[i] != '*'){
            len ++;
        }
        if(s[i] == '*'){
            flag = true;
        }

        if(s[i] == '?' || s[i] == '*'){
            cnt ++;
        }
    }

    if(k > len){
        if(flag){
            bool ok = false;
            for(int i = 0; i < s.length(); i ++){
                if(s[i] != '*' && s[i] != '?'){
                    cout << s[i];
                }

                if(!ok && i + 1 < s.length() && s[i + 1] == '*'){
        
                    for(int j = 1; j <= k - len; j ++){
                        cout << s[i];
                    }
                    ok = true;
                }
            }
        }else{
            cout << "Impossible";
        }
    }else if(k == len){
        for(int i = 0; i < s.length(); i ++){
            if(s[i] != '?' && s[i] != '*') cout << s[i];
        }
    }else{
        int t = len - k;
        if(cnt >= t){
            for(int i = 0; i < s.length(); i ++){
                if(s[i] != '?' && s[i] != '*'){
                    if(i + 1 < s.length() && (s[i + 1] == '?' || s[i + 1] == '*') && t){
                        t --;
                        continue;
                    }
                    cout << s[i];
                }
            }

        }else{
            cout << "Impossible";
        }
    }





    return 0;
}